function viewSamples( samples, parts, skip, thr, mgsum, epsilon, saveres, tasklist, gtasklist, nsize)
% Collect information about samples
%   Collect information about samples, some of them can be skipped. Divide 
%   samples on part by Y.
%
% Syntax
%   viewSamples( samples, parts, skip, thr, mgs, epsilon, saveres, tasklist, gtasklist, nsize)
%
% Input
%   samples   - cell array with sample ids
%   parts     - array with number of part
%   skip      - array with skipping flag (1 - skip, 0 - process)
%   thr       - grain detection threshold in degree
%   mgsum     - grain detection minimal grain size (MGS) in um^2
%   saveres   - save image to disk
%   tasklist  - task list
%   gtasklist - grain task list
%   nsize     - new sizes
%
% History
% 16.11.12  Original implementation.
% 04.12.12  Add resizing of EBSD data.
% 07.12.12  Fix parting of resized data. Modify desc.
% 28.12.12  Add printing of EBSD data size and step. Makeup output info.
%           Change dimension of MGS, now it is 'mgsum' in um^2.
% 16.04.13  Modify calculation of cell area (correcting results for hex). 

% Check mgs
if mgsum > 1
    warning('EBSDAM:TooBigMGS', 'Now ''mgs'' is in um^2, check ''mgs'' or comment this lines in ''viewSamples''')
    pause(5);
end

%% Processing
% Divide data
for i = 1:length(samples)
    
    % Sample id
    sid = samples{i};
    p = parts(i);
    
    disp('.');
    disp('+---------------------');

    % Skip sample
    if (skip(i) == 1)
        disp(['| Skip ' sid]);
        continue;
    else
        disp(['| Process ' sid]);
    end
    
    % Get EBSD data
    ebsd = eval([sid '_load']);
    
    % Get step size
    [ dx, dy, nx, ny ] = getStep( ebsd );
    ca = getCellArea( ebsd );
    fprintf(1,['Original Size of EBSD Data\n',...
        'Step: %f x %f um\n',...
        'Number %d x %d\n',...
        'Point area: %f um^2\n\n'], dx,dy, nx,ny, ca);
    
    % Calc MGS in point
    mgs = fix(mgsum/ca);
    fprintf(1,'MGS in point: %d\n', mgs);

    % Resize EBSD data
    if (iscell(nsize) && (length(nsize{i}) == 4))
        s = nsize{i};
        ebsd = cutEBSD(ebsd, s(1), s(2), s(3), s(4));
    end
                
    % If number of parts is more then 1
    if (p > 1)
        % Get max X and Y
        xmax = max(get(ebsd, 'x'));
        ymax = max(get(ebsd, 'y'));
        
        xmin = min(get(ebsd, 'x'));
        ymin = min(get(ebsd, 'y'));
        
        % Size of part
        dx = (xmax-xmin);
        dy = (ymax-ymin)/p;
        x0 = xmin;
        y0 = ymin;
        y1 = dy;
        
        % Make parts
        for j = 1:p
            ebsdp = cutEBSD(ebsd, x0,y0, dx,dy);
            viewAll(sid, j, ebsdp, saveres, thr, mgs, epsilon, tasklist, gtasklist);
            
            y0 = y1;
            y1 = y1 + dy;
        end
    else
        viewAll(sid, 0, ebsd, saveres, thr, mgs, epsilon, tasklist, gtasklist);
    end

end
